package mobi.hami.huapin.dao;

import java.util.List;

import mobi.hami.huapin.daobase.CrudMapper;
import mobi.hami.huapin.dto.PageDTO;
import mobi.hami.huapin.dto.ProductForUserDTO;
import mobi.hami.huapin.model.Product;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

@Repository
public interface ProductMapper extends CrudMapper<Product> {

    /**
     * 测试
     *
     * @param subject_id
     * @return
     */
    @Select("select  * from product where subject_id = #{subject_id}")
    public List<Product> getTestList(int subject_id);


    @Select("<script>"
            + "SELECT * FROM product "
            + "<where>"
            + "<if test='name != null'> <bind name='namenew' value=\"'%' + officename + '%'\" /> AND name like #{namenew}</if>"
            + "<if test='subject_id !=null'>AND subject_id = #{subject_id}</if>"
            + "<if test='first_sortid !=null'>AND first_sortid = #{first_sortid}</if>"
            + "</where>"

            + "</script>")
    public List<Product> getPageTest(Product smarBoxCompanyDTO);

    @Update("update Product set deleted=#{deleted} where id=#{id}")
    int  updateDelete (Product  product);


    /**
     * 用户前端查询
     * @param ids
     * @return
     */
    @Select("SELECT a.vodurl,a.id,b1.* FROM product a \n" +
            "LEFT JOIN (SELECT productid,skuname as name,id as skuid, min(group_price)AS group_price ,price,barcode,show_price FROM productsku where deleted=0  GROUP BY productid) b1 \n" +
            " ON b1.productid = a.id where a.id in (${ids}) and a.deleted =0  order by order_num asc")
    public List<ProductForUserDTO> getListForUser(@Param("ids")String ids);

}